package ap.project;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import ap.project.joystick.GameSurface;

public class Joystick extends Activity {
	String ip;
	int port;
	Socket socket;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        //set to full screen 
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,   
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		port = getPort();
		socket = createSocket();
        setContentView(new GameSurface(this, socket));

	}
	
	private Socket createSocket() {
		Socket s = null;
		try {
			s = new Socket(ip, port);
			Log.d(Constants.TAG, "Verbonden..");
		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return s;
	}

	private int getPort() {
		Bundle extras = this.getIntent().getExtras();
		if (extras != null) {
			ip = extras.getString("ip");
			if (extras.getInt("port") > 0) {
				return extras.getInt("port");
			}
		}
		return Constants.PORT;
	}


}
